package com.lxy.mytest;
import java.util.Scanner;


/**
 * Main方法
 * @author 雷晓艳
 */
public class Main {
	
	@SuppressWarnings("static-access")
	public static void main(String args[]){
		try{
			Operation o=new Operation(); 
			o.Read();
			Person p=new Person();
			Menu menu=new Menu();
			int on1 = 0;  //主菜单选择序号
			int on2 = 0;  //查询条件选择序号 
			Scanner sc = new Scanner(System.in);
		    menu.Menu1();      //显示主菜单
			on1=sc.nextInt();    //输入对通讯录的操作序号
			
			while(on1>=1&&on1<=5){
				while(on1==1){            //进行查询操作
			    	menu.Menu2();
			    	on2=sc.nextInt();
					
					while(on2==1){
						System.out.println("输入姓名:");   //姓名查询
						String name = sc.next();
						System.out.println(o.NameSearch(name));
					
						menu.Ask1();
						on1=sc.nextInt(); 
						break;
					}
					
					while(on2==2){
						System.out.println("输入电话：");    //电话查询
						String tel = sc.next();
						System.out.println(o.TelSearch(tel));
						menu.Ask1();
						on1=sc.nextInt(); 
						break;
						}
					
					while(on2!=1||on2!=2)
						break;
		        }

			  
				while(on1==2){      //删除操作    
				   o.Show();
				   System.out.println("请输入选择删除序号");
				   on2=sc.nextInt();     //输入要删除的序号
				   if(on2>=1){
					   String No=String.valueOf(on2);
					   o.Delete(No);
					   System.out.println("删除成功");
					   o.Show();
				   }
				   else
					   System.out.println("输入有误");
				   menu.Ask1();
				   on1=sc.nextInt(); 
				   o.writeFunction();
				   break;
			    }
			   
				while(on1==3){      //修改操作
				   String ans,name = null,tel=null,ads=null;
					//Person p=new Person(); 
					o.Show();
					System.out.println("输入修改序号：");
					String no=sc.next();
					for(int i=0;i<o.person.size();i++){
						if(o.person.get(i).getN().equals(no)){
							System.out.println(o.person.get(i).toString());
							name=o.person.get(i).getName();
							tel=o.person.get(i).getTel();
							ads=o.person.get(i).getAds();
						}
					}
					
					System.out.println("要修改姓名吗？[y]");
					ans=sc.next();   

					if(ans.equals("y")){
						System.out.println("请输入姓名：");
						name=sc.next();
					}
					
					System.out.println("要修改电话吗？[y]");
					ans=sc.next();  

					if(ans.equals("y")){
						System.out.println("请输入电话：");
					    tel=sc.next();
					}
					
					System.out.println("要修改职位吗？[y]");
					ans=sc.next();   

					if(ans.equals("y")){
						System.out.println("请输入职位：");
						ads=sc.next();
					}
					   o.Update(no,name,ads,tel);
					   o.Show();
					   menu.Ask1();
					   on1=sc.nextInt();
					   o.writeFunction();
			   }
			   
			   
				while(on1==4){
				   String name=null,tel=null,ads=null;
				   System.out.println("请输入添加信息：");
				   System.out.println("姓名：");
				   name=sc.next();
				   System.out.println("电话：");
				   tel=sc.next();
				   System.out.println("职位：");
				   ads=sc.next();
				   o.Add(name, ads, tel);
				   o.Show();
				   menu.Ask1();
				   on1=sc.nextInt();
				   o.writeFunction();
			   }
			   
				while(on1==5){       
					System.out.println("退出成功！");
					System.exit(0);
				}
		//o.writeFunction();
			}
		}

		
	
		catch  (Exception e)  {
            	System.out.println(e);
		}
	}

}
